package com.kingyun.gpsinspection.purificationservice.services.activitiservice.ext.personrule;

import com.google.common.base.Strings;
import com.kingyun.gpsinspection.purificationservice.common.activiti.ActivitiConstants;
import com.kingyun.gpsinspection.purificationservice.facade.model.activiti.BpmConfNode;
import com.kingyun.gpsinspection.purificationservice.services.activitiservice.ext.exception.AssignException;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;

import java.util.Arrays;

/**
 * 人员组配置规则
 * @author zjh
 * @since 20170615
 */
public class PersonGroupRule implements Rule {

    private static PersonGroupRule personGroupRule;

    private PersonGroupRule(){}

    public static PersonGroupRule getInstance(){
        if(personGroupRule==null){
            personGroupRule=new PersonGroupRule();
        }
        return personGroupRule;
    }

    @Override
    public void assigneRule(ActivityExecution execution,TaskEntity task, BpmConfNode bpmConfUser) {
        if(Strings.isNullOrEmpty(bpmConfUser.getUserValue())){
            throw new AssignException("没有相关用户组");
        }
        String[] split = bpmConfUser.getUserValue().toString().split(ActivitiConstants.PERON_SEPARATE);
        task.addCandidateUsers(Arrays.asList(split));
    }
}
